//
//  AVFormatContext.cpp
//  VideoParse
//
//  Created by xiaerfei on 2020/4/1.
//  Copyright © 2020 erfeixia. All rights reserved.
//

#include "AVFormatContext.hpp"
#include "File.hpp"
#include "FLVDemuxer.hpp"


AVFormatContext::AVFormatContext() {
    metadata = new std::unordered_map<std::string, std::string>();
}

int AVFormatContext::open_input(char *url, void *fmt, void *options) {
    this->pb = new AVIOContext();
    this->pb->ffRRL = new File(url,1);
    int ret = read_header();
    
    return 0;
}


int AVFormatContext::find_stream_info(void *options) {
    this->demuxer = new FLVDemuxer();
    return 0;
}

int AVFormatContext::read_header() {
    this->demuxer->read_header(this);
    return 1;
}

int AVFormatContext::read_packet(void *pkt) {
    this->demuxer->read_packet(this, pkt);
    return 1;
}

int AVFormatContext::read_close() {
    this->demuxer->read_close(this);
    return 1;
}

int AVFormatContext::read_seek(int stream_index, int64_t timestamp, int flags) {
    this->demuxer->read_seek(this, stream_index, timestamp, flags);
    return 1;
}

void AVFormatContext::add_value_for_key(std::string value, std::string key) {
    metadata->insert(std::pair<std::string, std::string>(key,value));
}

std::string AVFormatContext::value_for_key(std::string key) {
    return metadata->at(key);
}

